using System;
using System.Threading;
using Common.Logging;
using System.IO;

namespace Quartz.Server
{
    /// <summary>
    /// A sample job that just prints info on console for demostration purposes.
    /// </summary>
    public class SampleJob : IJob
    {
        private const string FolderName = "QuartzDemo1";
        private const string SubfolderName = "Log";
        private static readonly ILog logger = LogManager.GetLogger(typeof(SampleJob));

        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// </summary>
        /// <remarks>
        /// The implementation may wish to set a  result object on the 
        /// JobExecutionContext before this method exits.  The result itself
        /// is meaningless to Quartz, but may be informative to 
        /// <see cref="IJobListener" />s or 
        /// <see cref="ITriggerListener" />s that are watching the job's 
        /// execution.
        /// </remarks>
        /// <param name="context">The execution context.</param>
        public void Execute(IJobExecutionContext context)
        {
            ////logger.Info("SampleJob running...");
            ////Thread.Sleep(TimeSpan.FromSeconds(5));
            ////logger.Info("SampleJob run finished.");
            ////
            var strDirPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + FolderName + "\\" + SubfolderName;
            if (System.IO.Directory.Exists(strDirPath) == false)
            {
                System.IO.Directory.CreateDirectory(strDirPath);
            }
            string strLogPath = string.Format("{0}\\QuartzDemo_{1}_{2}.txt", strDirPath, DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString());
            FileStream file = File.Exists(strLogPath) ? new FileStream(strLogPath, FileMode.Append, FileAccess.Write) : new FileStream(strLogPath, FileMode.CreateNew, FileAccess.Write);
            var sw = new StreamWriter(file);
            sw.WriteLine("{0} : NOTE # {1}", DateTime.Now, "Current Time is : {0}", DateTime.Now);
            sw.Close();
            file.Close();
        }
   
    
    }
}